package com.lavegue.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import com.lavegue.common.BaseService;
import com.lavegue.common.Page;
import com.lavegue.dao.ManageMsgDao;
import com.lavegue.model.ManageMsg;
import com.lavegue.model.UserInfo;
import com.lavegue.service.ManageMsgService;

/**
 * author: luoweibin
 * date:2011-12-29
 * description:
 *
 */
public class ManageMsgServiceImpl extends BaseService<ManageMsg, Integer, ManageMsgDao> implements ManageMsgService {

	public Page<ManageMsg> findPage(int maybeSend, Date startTime, Date endTime, String title,
			int type, int group, int pageNo, int pageSize) {
		return this.getDao().findPage(maybeSend, startTime, endTime, title, type, group, pageNo, pageSize);
	}

	public Page<ManageMsg> findPageByTypeAndGroup(int type, int group,
			int pageNo, int pageSize,  UserInfo user, String title) {
		return this.getDao().findPageByTypeAndGroup(type, group, pageNo, pageSize, user, title);
	}
	//tzf 首页模糊查询根据标题
	public Page<ManageMsg> findManageMsgByContent(int pageNo,int pageSize,int typeid,String likeName)
	{
		return this.getDao().findManageMsgByContent(pageNo, pageSize, typeid, likeName);
	}

	public List<ManageMsg> findRandomList(int number) {
		List<ManageMsg> list = this.getDao().findMaybeSendMsgs();
		Random r = new Random(System.currentTimeMillis());
		List<ManageMsg> result = new ArrayList<ManageMsg>();
		int numberNew = number;
		if (number >list.size()) {
			numberNew = list.size();
		}
		int cnt = 0;
		
		while (cnt != numberNew) {
			ManageMsg mm = list.get(r.nextInt(list.size()));
			if (!result.contains(mm)) {
				result.add(mm);
			}
			cnt = result.size();
		}
		return result;
	}
}

